package cn.yudao.ymcc.mq.producer;

import cn.yudao.ymcc.domain.MediaFile;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

@Component
public class MediaProducer {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;


    public boolean sendProductMessage(MediaFile mediaFile){
        Message<MediaFile> build = MessageBuilder.withPayload(mediaFile).build();
        SendResult sendResult = rocketMQTemplate.syncSend("topic-media:rag-media", build);
        if (sendResult.getSendStatus() == SendStatus.SEND_OK){
            return true;
        }
        return false;
    }


}
